import { fileURLToPath, URL } from 'node:url'

import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite' // 按需加载自定义组件
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// import PurgeIcons from 'vite-plugin-purge-icons'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'


// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {


  console.log('/////////',path.resolve(process.cwd(), 'src/assets/svg'))

  return {
    plugins: [
      vue(),
      // PurgeIcons(),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
        symbolId: 'icon-[dir]-[name]',
        svgoOptions: true
      }),
      Components({
        deep: true, // 搜索子目录
        dirs: ['src/components'],
        resolvers: [ ElementPlusResolver() ],
        dts: 'src/types/auto-components.d.ts'
      }),
      AutoImport ({
        imports: ["vue", "vue-router","pinia"], //自动引入vue的ref、toRefs、onmounted等，无需在页面中再次引入
        resolvers:[ElementPlusResolver()],
        dts: 'src/types/auto-imports.d.ts'
      })
    ],
    resolve: {
      extensions: ['.mjs', '.js', '.ts', '.d.ts', '.jsx', '.tsx', '.json', '.scss', '.css'],
      alias: { // 起别名：比如给 ./src起别名 @
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    }
  }
})
